<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/8/28
 * Time: 15:53
 */

namespace Controller;

class IndexController extends TooController {
    //首页
    public function index(){
        $this->view->display();
    }

    //退出
    public function tc(){
        //删除session 和cookie
        unset($_SESSION[SHOP]);

        setcookie('admin_name','',time()-1,'/');

        $this->success('退出成功','Login','login');
    }

    //系统设置
    public function system_base(){
        if($_POST){
            //修改数据
            $arr=$_POST;
            unset($arr['file']);
            if(empty($arr['wbanner'])){
                unset($arr['wbanner']);
            }
            $this->pdo->pdo_upd($arr,'s_set'," id = '{$_POST['id']}'");
        }

        //查询数据
        $list=$this->pdo->pdo_sel("select * from s_set  limit 1");
        $this->view->assign('list',$list);
        $this->view->display();

    }

    //图片上传
    public function slogo(){
       $imag=$this->imgFile($_FILES['file'],'/Public/Admin/wset/');

       $this->retuAjax(array('code'=>'0','msg'=>'上传成功','data'=>array('src'=>$imag)));
    }

    //栏目管理
    public function system_category(){
        //是否有id参数,实现批量删除
        if($_GET['id']){
            $id=trim($_GET['id'],','); //传递过来的参数多了一个 , 号
            if($this->pdo->pdo_del('s_lm'," id in ($id)")){
                $this->retuAjax(array('type'=>1,'msg'=>'删除成功'));
            }else{
                $this->retuAjax(array('type'=>2,'msg'=>'删除失败'));
            }

        }

        $arr=$this->pdo->pdo_sel("select * from s_lm order by sort desc",2);
        $this->view->assign('arr',$arr);
        $this->view->display();
    }

    //添加栏目
    public function system_category_add(){
        if($_POST){
           $arr=array();
           $arr['title']=$_POST['title'];
           $arr['sort']=$_POST['sort'];

           if($this->pdo->pdo_ins($arr,'s_lm')){
               $this->retuAjax(array('type'=>1,'msg'=>'操作成功'));
           }else{
               $this->retuAjax(array('type'=>2,'msg'=>'操作失败'));
           }
        }
       $this->view->display();
    }

    //删除栏目
    public function system_category_del(){
        $id=$_GET['id'];
        if($id){
            if($this->pdo->pdo_del("s_lm"," id = $id")){
                $this->retuAjax(array('type'=>'1','msg'=>'删除成功'));
            }else{
                $this->retuAjax(array('type'=>'2','msg'=>'删除失败'));
            }
        }else{
            $this->retuAjax(array('type'=>'2','msg'=>'非法操作'));
        }
    }

    //修改栏目 --- 修改和添加使用一个页面
    public function system_category_edit(){
        if($_POST){
            $id=$_POST['id'];
            $arr=array();
            $arr['title']=$_POST['title'];
            $arr['sort']=$_POST['sort'];
            if($this->pdo->pdo_upd($arr,'s_lm'," id = $id")){
                $this->retuAjax(array('type'=>1,'msg'=>'操作成功'));
            }else{
                $this->retuAjax(array('type'=>2,'msg'=>'操作成功'));
            }
        }
        $id=$_GET['id'];
        $list=$this->pdo->pdo_sel("select * from s_lm where id = $id");
        $this->view->assign('list',$list);
        $this->view->display('system_category_add');
    }
}







